import logging
import redis
from redis import StrictRedis


class Config(object):
    """项目配置"""

    DEBUG = True
    SQLALCHEMY_DATABASE_URI="mysql://root:mysql@127.0.0.1:3306/xinwen"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    """将ｓｅｓｓｉｏｎ储存在redis，因为如果将ｓｅｓｓｉｏｎ放在ｃｏｏｋｉｅ里面
    遇到多并发会造成服务器崩，放在ｒｅｄｉｓ或者ｍｙｓｑｌ数据库中
    会好点"""
    SESSION_TYPE = "redis"
    """把ｓｅｓｓｉｏｎ加密签名处理"""
    SESSION_USE_SIGNER = True
    """使用redis实例,将redis和python进行交互"""
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    """设置SESSION的有效期"""
    PERMANENT_SESSION_LIFETIME = 86400
    """在配置中传入日志等级"""
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发环境的配置"""
    DEBUG = True


class ProdutionConfig(Config):
    """生产环境下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    """单元测试下的配置"""
    DEBUG = True
    TESTING = True

config = {
    "development": DevelopmentConfig,
    "prodution": ProdutionConfig,
    "testing": TestingConfig
}